/*
 * Copyright (c) 2020 Carnegie Lee
 * All rights reserved
 */
package com.geekc.threadpool.thread;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * Thread Factory默认实现类
 * @author Carnegie Lee
 */
public class DefaultThreadFactory implements java.util.concurrent.ThreadFactory {
    private final String prefixThreadName;
    private final AtomicInteger nextId = new AtomicInteger(1);

    public DefaultThreadFactory(String prefixThreadName) {
        this.prefixThreadName = prefixThreadName;
    }

    @Override
    public Thread newThread(Runnable task) {
        String threadName = prefixThreadName + nextId.getAndIncrement();
        Thread thread = new Thread(null, task, threadName, 0);
        return thread;
    }
}
